package com.ml.springboot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ml.springboot.mapper.LeaveMapper;
import com.ml.springboot.pojo.Leave;
import com.ml.springboot.pojo.VO.LeaveVO;
import com.ml.springboot.pojo.query.LeaveQuery;
import com.ml.springboot.service.ILeaveService;
import com.ml.springboot.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LeaveServiceImpl implements ILeaveService {
    @Autowired
    private LeaveMapper leaveMapper;

    @Override
    public PageResult list(LeaveQuery leaveQuery) {
        PageHelper.startPage(leaveQuery.getPage(), leaveQuery.getLimit());
        //当前分页数据
        List<LeaveVO> list = leaveMapper.list(leaveQuery);
        PageInfo pageInfo = new PageInfo(list);
        int totalCount = (int) pageInfo.getTotal();
        return new PageResult(0,"",totalCount,list);
    }

    @Override
    public void deletedById(Integer id) {
        leaveMapper.deleteById(id);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        for (Integer id : ids) {
            leaveMapper.deleteById(id);
        }
    }

    @Override
    public void add(Leave leave) {
        leaveMapper.add(leave);
    }

    @Override
    public Leave selectById(Integer id) {
        return leaveMapper.selectById(id);
    }

    @Override
    public void update(Leave leave) {
        leaveMapper.update(leave);
    }

    @Override
    public void pass(Integer id) {
        leaveMapper.pass(id);
    }

    @Override
    public void nopass(Integer id) {
        leaveMapper.nopass(id);
    }

    @Override
    public List<LeaveVO> leaveCount() {
       return leaveMapper.leaveCount();
    }


}
